package com.demo.webflux.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/article")
public class ArticleController {

	@Autowired
	private ArticleService articleService;

	@PostMapping("")
	public Flux<Article> save(@RequestBody final Mono<Article> article){
		return articleService.save(article);
	}

	@GetMapping("/{id}")
	public Mono<Article> findOne(@PathVariable("id") final String id){
		return articleService.findOne(id);
	}

    @GetMapping("")
	public Flux<Article> findAll(){
		return articleService.findAll();
	}

    @DeleteMapping("/{id}")
    public Mono<Void> delete(@PathVariable("id") final String id){
    	return articleService.delete(id);
    }

}